/**
 * Created by wdl on 2017/11/1.
 */
var methods = {
// 打开一个窗体
    windowOpen:  function (url, name, width, height){
    var top=parseInt((window.screen.height-height)/2,10),left=parseInt((window.screen.width-width)/2,10),
        options="location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,"+
            "resizable=yes,scrollbars=yes,"+"width="+width+",height="+height+",top="+top+",left="+left;
    window.open(url ,name , options);
},
    // 恢复提示框显示
    resetTip: function(){
    top.$.jBox.tip.mess = null;
},

// 关闭提示框
    closeTip:function (){
    top.$.jBox.closeTip();
},

//显示提示框
    showTip:function (mess, type, timeout, lazytime){
     methods.resetTip()();
    setTimeout(function(){
        top.$.jBox.tip(mess, (type == undefined || type == '' ? 'info' : type), {opacity:0,
            timeout:  timeout == undefined ? 2000 : timeout});
    }, lazytime == undefined ? 500 : lazytime);
},

// 显示加载框
    loading:function (mess){
    if (mess == undefined || mess == ""){
        mess = "正在提交，请稍等...";
    }
     methods.resetTip()();
    top.$.jBox.tip(mess,'loading',{opacity:0});
},

// 关闭提示框
    closeLoading:function (){
    // 恢复提示框显示
     methods.resetTip()();
    // 关闭提示框
    closeTip();
},

// 警告对话框
    alertx:function (mess, closed){
    top.$.jBox.info(mess, '提示', {closed:function(){
        if (typeof closed == 'function') {
            closed();
        }
    }});
    top.$('.jbox-body .jbox-icon').css('top','35px');
},

// 确认对话框
    confirmx:function (mess, href, closed){
    top.$.jBox.confirm(mess,'提示',function(v,h,f){
        if(v=='ok'){
            if (typeof href == 'function') {
                href();
            }else{
                methods.resetTip(); //loading();
                location = href;
            }
        }
    },{buttonsFocus:1, closed:function(){
        if (typeof closed == 'function') {
            closed();
        }
    }});
    top.$('.jbox-body .jbox-icon').css('top','35px');
    return false;
},

// 提示输入对话框
    promptx:function (title, lable, href, closed){
    top.$.jBox("<div class='form-search' style='padding:20px;text-align:center;'>" + lable + "：<input type='text' id='txt' name='txt'/></div>", {
        title: title, submit: function (v, h, f){
            if (f.txt == '') {
                top.$.jBox.tip("请输入" + lable + "。", 'error');
                return false;
            }
            if (typeof href == 'function') {
                href();
            }else{
                 methods.resetTip()(); //loading();
                location = href + encodeURIComponent(f.txt);
            }
        },closed:function(){
            if (typeof closed == 'function') {
                closed();
            }
        }});
    return false;
},

// 添加TAB页面
    addTabPage:function (title, url, closeable, $this, refresh){
    top.$.fn.jerichoTab.addTab({
        tabFirer: $this,
        title: title,
        closeable: closeable == undefined,
        data: {
            dataType: 'iframe',
            dataLink: url
        }
    }).loadData(refresh != undefined);
},

}
